package com.actions.bluetoothbox2.util;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.actions.bluetoothbox2.R;

/**
 * Created by liuyong on 2017/12/25.
 */

public class PopupMusicSelecter extends PopupWindow {

    private onSelecteListener selected;
    private int pos = 0;
    public int[] imgID = new int[]{R.drawable.ic_music_1, R.drawable.ic_music_2, R.drawable.ic_music_3,
            R.drawable.ic_music_4, R.drawable.ic_music_5, R.drawable.ic_music_6};
    private PopMusicSelectAdapter adapter;

    public PopupMusicSelecter(Context context) {
        super(context);
        View view = LayoutInflater.from(context).inflate(R.layout.pop_musicselect_layout, null);
        GridView pop_grid = (GridView) view.findViewById(R.id.pop_grid);
        adapter = new PopMusicSelectAdapter(context, imgID);
        pop_grid.setAdapter(adapter);
        pop_grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                selected.onSelected(position, imgID[position]);
                dismiss();
            }
        });

        setContentView(view);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(LinearLayout.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
//        this.setAnimationStyle(R.style.mypopwindow_anim_style);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
    }

    public void setSelected(onSelecteListener selected) {
        this.selected = selected;
    }


    public interface onSelecteListener {
        void onSelected(int position, int imgID);
    }

}
